package part18;

import java.io.*;

/**
 * @author wcj
 * @Date 2021/6/3 17:46
 * @Version 1.0
 */
public class Part1812 {

    /**
     * 使用DataOutputStream和DataInputStream可以完美的存储和读取文件数据，并且数据的格式保证不变
     * 但是缺陷是，我们需要知道存储的数据的确切的位置信息，这就意味着我们需要在文件中存放额外的信息来标识数据的确切位置
     *
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("./src/part18/Data.txt")));
        out.writeDouble(3.1415926);
        out.writeUTF("That was pi");
        out.writeDouble(2.520);
        out.writeUTF("Square root is 2");
        out.close();

        DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream("./src/part18/Data.txt")));
        System.out.println(in.readDouble());
        System.out.println(in.readUTF());
        System.out.println(in.readDouble());
        System.out.println(in.readUTF());
    }
}
